#include "qmyselfvideowidget.h"

QMyselfVideoWidget::QMyselfVideoWidget(QWidget *parent):QVideoWidget(parent)
{

}

void QMyselfVideoWidget::setMediaPlayer(QMediaPlayer *player)
{
    thePlayer = player;
}


void QMyselfVideoWidget::keyPressEvent(QKeyEvent *event)
{
    //如果用户按下了 ESC键,并且窗口是全屏状态
    if((event->key() == Qt::Key_Escape) && (isFullScreen()))
    {
        //退出全屏
        setFullScreen(false);
        event->accept();

        //显示调用父类 keyPressEvent ,
        //能够保证QVideoWidget自身的按键事件处理逻辑依然可以正常运行
        QVideoWidget::keyPressEvent(event);
    }
}

void QMyselfVideoWidget::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt::LeftButton)
    {
        if(thePlayer->state() == QMediaPlayer::PlayingState)
        {
            thePlayer->pause();
        }
        else
        {
            thePlayer->play();
        }
    }

    QVideoWidget::mousePressEvent(event);
}
